package org.starapp.rbac.entity;

import javax.persistence.GenerationType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Column;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableList;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author wangqiang@cisoft.com.cn
 *
 */
@Entity
@Table(name = "rbac_departments")
public class Departments implements Serializable{
		
				
		/**
		 * DEPARTMENT_ID
		 */
		private String departmentId;
				
		/**
		 * DEPARTMENT_NAME
		 */
		private String departmentName;
		
		/**
		 * Departments
		 */
		private Departments departments;
		


		private List<Users> usersM2MList;				

		private List<Users> usersList;				

		
				
		@Id
		@Column(name="DEPARTMENT_ID")
		@NotBlank
		public String getDepartmentId(){
			return this.departmentId;
		}
		
		public void setDepartmentId(String departmentId){
			this.departmentId = departmentId;
		}
		
				
		@NotBlank
		public String getDepartmentName(){
			return this.departmentName;
		}
		
		public void setDepartmentName(String departmentName){
			this.departmentName = departmentName;
		}
		
		
				
		@ManyToMany
		@JoinTable(name = "rbac_departments_users", joinColumns={@JoinColumn(name="DEPARTMENT_ID") },inverseJoinColumns={@JoinColumn(name="USER_ID")})		
		public List<Users> getUsersM2MList(){
			return this.usersM2MList;
		}
		
		public void setUsersM2MList(List<Users> usersM2MList){
			this.usersM2MList = usersM2MList;
		}
				
		@OneToMany(mappedBy = "departments")
		public List<Users> getUsersList(){
			return this.usersList;
		}
		
		public void setUsersList(List<Users> usersList){
			this.usersList = usersList;
		}

		@OneToOne
		@JoinColumn(name = "PARENT_DEPARTMENT_ID")					
		public Departments getDepartments(){
			return this.departments;
		}
		
		public void setDepartments(Departments departments){
			this.departments = departments;
		}

		
		@Override
		public String toString() {
			return ToStringBuilder.reflectionToString(this);
		}
	
	}

